package com.bl.student.manager.controller.apply;

import com.bl.student.common.ApiResponseBody;
import com.bl.student.dao.model.ApplyEntity;
import com.bl.student.manager.controller.BaseController;
import com.bl.student.service.biz.apply.ApplyService;
import com.bl.student.service.vo.DelBody;
import com.bl.student.service.vo.DelListBody;
import com.bl.student.service.vo.apply.ApplyAddVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import com.bl.student.service.vo.apply.ApplyListVo;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;



/**
 * Created by liangweikang on 18/1/29.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/student/manager/apply"})
@Api(value = "申请", description = "申请相关api")
public class ApplyController  extends BaseController {

    @Autowired
    ApplyService applyService;

//    @ApiOperation(value = "根据乙方id获取乙方申请记录列表", notes = "乙方申请记录 ")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "乙方id", required = true, paramType = "query", dataType = "String"),
//            @ApiImplicitParam(name = "page", value = "页数", required = true, paramType = "query", dataType = "int", defaultValue = "1"),
//            @ApiImplicitParam(name = "size", value = "每页大小", required = true, paramType = "query", dataType = "int", defaultValue = "10")})
//
//    @GetMapping(value = {"/get_list"})
//    public ApiResponseBody<ApplyListVo> getLists(
//            @RequestParam(value = "id", required = true) String id,
//            @RequestParam(value = "page", required = true, defaultValue = "1") int page,
//            @RequestParam(value = "size", required = true, defaultValue = "10") int size,
//            HttpServletRequest request) {
//        Pageable pageable = new PageRequest(page - 1, size);
//        ApplyListVo applyListVo = applyService.getApplyLists(id, pageable );
//
//        return ApiResponseBody.createSuccessBody(applyListVo);
//    }
//
//    @ApiOperation(value = "根据甲方id和taskid获取甲方发布任务的申请列表", notes = "甲方发布任务申请记录 ")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "partyaid", value = "甲方id", required = true, paramType = "query", dataType = "String"),
//            @ApiImplicitParam(name = "taskid", value = "任务id", required = true, paramType = "query", dataType = "String"),
//            @ApiImplicitParam(name = "page", value = "页数", required = true, paramType = "query", dataType = "int", defaultValue = "1"),
//            @ApiImplicitParam(name = "size", value = "每页大小", required = true, paramType = "query", dataType = "int", defaultValue = "10")})
//
//    @GetMapping(value = {"/get_task_list"})
//    public ApiResponseBody<ApplyListVo> getLists(
//            @RequestParam(value = "partyaid", required = true) String partyaid,
//            @RequestParam(value = "taskid", required = true) String taskid,
//            @RequestParam(value = "page", required = true, defaultValue = "1") int page,
//            @RequestParam(value = "size", required = true, defaultValue = "10") int size,
//            HttpServletRequest request) {
//        Pageable pageable = new PageRequest(page - 1, size);
//        ApplyListVo applyListVo = applyService.getApplyListsPartya(partyaid, taskid, pageable );
//
//        return ApiResponseBody.createSuccessBody(applyListVo);
//    }


    @ApiOperation(value = "根据甲方id，乙方id、taskid、时间获取申请列表", notes = "申请记录 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "partyaid", value = "甲方id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "partybid", value = "乙方id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taskid", value = "任务id", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页数", required = true, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = true, paramType = "query", dataType = "int", defaultValue = "10")})

    @GetMapping(value = {"/get_all_list"})
    public ApiResponseBody<ApplyListVo> getLists(
            @RequestParam(value = "partyaid", required = false) String partyaid,
            @RequestParam(value = "partybid", required = false) String partybid,
            @RequestParam(value = "taskid", required = false) String taskid,
            @RequestParam(value = "page", required = true, defaultValue = "1") int page,
            @RequestParam(value = "size", required = true, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);
        ApplyListVo applyListVo = applyService.getAllApplyLists(partyaid, partybid, taskid, pageable  );

        return ApiResponseBody.createSuccessBody(applyListVo);
    }

    @ApiOperation(value = "删除单条记录", notes = "删除单条记录 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {


        applyService.del(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除批量", notes = "删除批量申请记录信息 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_list"})
    public ApiResponseBody delList(
            @Valid @RequestBody DelListBody body, BindingResult result,
            HttpServletRequest request) {

        applyService.delList(body);

        return ApiResponseBody.createSuccessBody(null);
    }

//    @ApiOperation(value = "增加申请记录信息", notes = "增加申请记录信息 ")
//    @ApiImplicitParams({})
//    @PostMapping(value = {"/add"})
//    public ApiResponseBody add(
//            @Valid @RequestBody ApplyAddVo body, BindingResult result,
//            HttpServletRequest request) {
//
//        ApiResponseBody validResult = validParams(result);
//        if (validResult != null) {
//            return validResult;
//        }
//        String userid = "80bf42ac3abd47d39c7af5f9da6c19fb";
//        applyService.add(body,userid);
//
//        return ApiResponseBody.createSuccessBody(null);
//    }

}
